home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 39 / Issue 39.iso / pc / PCSoftware / RoboHelp / DISK1 / DATA.1 / bsscohrs.jar / HelpLauncher.java < prev   
Encoding:
Java Source  |  2000-05-02  |  13.7 KB  |  482 lines

  1. /* Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved. */
  2.  
  3.               /*
  4.  * Demo.java
  5.  *
  6.  * Copyright (c) 1997 Oracle Corp, Inc. All Rights Reserved.
  7.  *
  8.  * Oracle grants you ("Licensee") a non-exclusive, royalty free, license
  9.  * to use, modify and redistribute this software in source and binary code
  10.  * form, provided that i) this copyright notice and license appear on all
  11.  * copies of the software; and ii) Licensee does not utilize the software
  12.  * in a manner which is disparaging to Oracle.
  13.  *
  14.  * This software is provided "AS IS," without a warranty of any kind. ALL
  15.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  16.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  17.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ORACLE AND ITS LICENSORS SHALL NOT BE
  18.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  19.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL ORACLE OR ITS
  20.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  21.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  22.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  23.  * OR INABILITY TO USE SOFTWARE, EVEN IF ORACLE HAS BEEN ADVISED OF THE
  24.  * POSSIBILITY OF SUCH DAMAGES.
  25.  *
  26.  * This software is not designed or intended for use in on-line control of
  27.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  28.  * the design, construction, operation or maintenance of any nuclear
  29.  * facility. Licensee represents and warrants that it will not use or
  30.  * redistribute the Software for such purposes.
  31.  */
  32.  
  33.  
  34. import oracle.help.Help;
  35. import oracle.help.library.Book;
  36. import oracle.help.library.helpset.HelpSet;
  37. import oracle.help.library.helpbook.HelpBook;
  38.  
  39. import java.net.URL;
  40. import java.util.Enumeration;
  41. import java.util.Vector;
  42. import java.lang.Class;
  43.  
  44. //Launch OracleHelp
  45. public class HelpLauncher
  46. {
  47.   public HelpLauncher(String a_strHelpSet, String a_strHelpId)
  48.   {
  49.     //HelpLauncher31(a_strHelpSet, String a_strHelpId);
  50.     // HelpLauncher32(a_strHelpSet,a_strHelpId);
  51.     HelpLauncher322(a_strHelpSet, a_strHelpId);
  52.   }
  53.  
  54.   //Help Launcher for OracleHelp 3.2.2/4.1.2
  55.   public boolean HelpLauncher322(String a_strHelpSet, String a_strHelpId)
  56.   {
  57.     Help        help         = null;
  58.     HelpSet     helpset      = null;
  59.     String      strHsUrl     = "";
  60.     String      strJarName   = "";
  61.  
  62.  
  63.     //make help which can shut down JVM..
  64.     Class htmlBrowserClass = null;
  65.     try
  66.     {
  67.       htmlBrowserClass = Class.forName("oracle.help.htmlBrowser.ICEBrowser");
  68.     }
  69.     catch (Exception e)
  70.     {
  71.       htmlBrowserClass = null;
  72.       System.err.println("HelpLauncher : Failed to load ICEBrowser");
  73.     }
  74.     help = new Help(htmlBrowserClass, false, true, true);
  75.  
  76.     boolean bSuccess = true;
  77.  
  78.     if (a_strHelpSet.endsWith(".jar"))
  79.     {
  80.       //Compressed help in jar,  the class inside the jar should be "FileName"+"DocHelpSet"
  81.       //and located either in "FileName".toLowCase() package or Unnamed Package
  82.       strJarName = new String("");
  83.       strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
  84.     }
  85.     else if (a_strHelpSet.endsWith(".hs"))
  86.     {
  87.         //Helpset file
  88.         if (a_strHelpSet.charAt(0) == '/')
  89.           strHsUrl = "file:"  + a_strHelpSet;
  90.         else
  91.           strHsUrl = "file:/" + a_strHelpSet;
  92.     }
  93.     else
  94.     {
  95.         System.out.println("Unknown file extension name.");
  96.         bSuccess = false;
  97.     }
  98.  
  99.     //Build helpset object
  100.     if (bSuccess)
  101.     {
  102.       try
  103.       {
  104.         if (strHsUrl.length () != 0)
  105.         {
  106.           //a hs file
  107.           helpset = new HelpSet(new URL(strHsUrl));
  108.         }
  109.         else if (strJarName.length() != 0)
  110.         {
  111.           //a jar file
  112.           String strPackageName = strJarName;
  113.           String strClsName = "";
  114.  
  115.           //try to find the class in package
  116.           Class  clsName = null;
  117.           boolean bFindClass = false;
  118.           try
  119.           {
  120.             strClsName = strPackageName +"." + strJarName + "DocHelpSet";
  121.             clsName = Class.forName(strClsName);
  122.             bFindClass = true;
  123.           }
  124.           catch(Exception e)
  125.           {
  126.             //Ignore
  127.           }
  128.  
  129.           if (!bFindClass)
  130.           {
  131.             //try to find the class in unnamed package
  132.             try
  133.             {
  134.               strClsName = strJarName + "DocHelpSet";
  135.               clsName = Class.forName(strClsName);
  136.               bFindClass = true;
  137.             }
  138.             catch(Exception e)
  139.             {
  140.                //Ignore
  141.             }
  142.           }
  143.  
  144.           if (bFindClass)
  145.           {
  146.             String strHsName = strJarName + ".hs";
  147.             helpset = new HelpSet(clsName, strHsName);
  148.           }
  149.           else
  150.           {
  151.              System.out.println("Can not find class in jar file:" + strJarName + ".class" );
  152.              bSuccess = false;
  153.           }
  154.         }
  155.         else
  156.         {
  157.           System.out.println("No file name ?!");
  158.           bSuccess = false;
  159.         }
  160.       }
  161.       catch (Exception e)
  162.       {
  163.         e.printStackTrace();
  164.         bSuccess = false;
  165.       }
  166.     }
  167.  
  168.     if (!bSuccess)
  169.     {
  170.       System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
  171.     }
  172.     else
  173.     {
  174.       Book book = (Book)helpset;
  175.       help.addBook(book);
  176.       help.showNavigatorWindow();
  177.  
  178.     }
  179.     return bSuccess;
  180.   }
  181.  
  182.  
  183.   //Use same command line parameter as JavaHelp Launch
  184.   public static void main(String[] args)
  185.   {
  186.     String strHelpset   = "";
  187.     String strHelpPath  = "";
  188.     String strHelpsetUrl= "";
  189.     String strHelpId    = "";
  190.     String strSize      = "";
  191.  
  192.     while (args.length > 0)
  193.     {
  194.         if (args[0].equals("-helpset"))
  195.         {
  196.             // Name of HelpSet.  Look for it in the classpath
  197.              args = shiftArgs(args, 1);
  198.              strHelpset = args[0];
  199.              args = shiftArgs(args, 1);
  200.         } else if (args[0].equals("-helppath")) {
  201.             // This is a 1.2-only feature
  202.             args = shiftArgs(args, 1);
  203.             strHelpPath = args[0];
  204.             args = shiftArgs(args, 1);
  205.          } else if (args[0].equals("-hsURL")) {
  206.             // This is the given URL for the HelpSet
  207.              args = shiftArgs(args, 1);
  208.              strHelpsetUrl = args[0];
  209.              args = shiftArgs(args, 1);
  210.          } else if (args[0].equals("-id")) {
  211.             // This is the given ID in a HelpSet to display
  212.              args = shiftArgs(args, 1);
  213.              strHelpId = args[0];
  214.              args = shiftArgs(args, 1);
  215.          } else if (args[0].equals("-size")) {
  216.              // This is the given ID in a HelpSet to display
  217.              args = shiftArgs(args, 1);
  218.              strSize = args[0];
  219.              args = shiftArgs(args, 1);
  220.          } else if (args[0].equals("-debug")) {
  221.              args = shiftArgs(args, 1);
  222.          } else {
  223.              usage(null);
  224.          }
  225.    }
  226.    HelpLauncher demo = new HelpLauncher(strHelpset, strHelpId);
  227.   }
  228.  
  229.    //Usage: Same as JavaHelp
  230.    protected static void usage(String msg) {
  231.         if (msg != null) {
  232.             System.err.println("HelpLauncher: " + msg);
  233.         }
  234.         System.err.println("Usage: HelpLauncher [-helpset name | -helppath path | -hsURL spec | -id target | -size width,height ]");
  235.         System.exit(1);
  236.     }
  237.  
  238.    //Shift argv
  239.    private static String[] shiftArgs(String args[], int step) {
  240.         int count = args.length;
  241.         String back[] = new String[count-step];
  242.         for (int i=0; i<count-step; i++) {
  243.             back[i] = args[i+step];
  244.         }
  245.         return back;
  246.     }
  247.  
  248.  
  249.  
  250. /*
  251.   //Help Launcher for OracleHelp 3.1.x
  252.   public boolean HelpLauncher31(String a_strHelpSet, String a_strHelpId)
  253.   {
  254.     Help        help          = new Help();
  255.     HelpSetFile helpset       = null;
  256.     String      strHsUrl      = "";
  257.     String      strJarName    = "";
  258.  
  259.     boolean bSuccess = true;
  260.  
  261.     if (a_strHelpSet.endsWith(".jar"))
  262.     {
  263.       //Compressed help in jar,  the class inside the jar should be "FileName"+"DocHelpSet"
  264.       //and located either in "FileName".toLowCase() package or Unnamed Package
  265.       strJarName = new String("");
  266.       strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
  267.     }
  268.     else if (a_strHelpSet.endsWith(".hs"))
  269.     {
  270.         //Helpset file
  271.         if (a_strHelpSet.charAt(0) == '/')
  272.           strHsUrl = "file:"  + a_strHelpSet;
  273.         else
  274.           strHsUrl = "file:/" + a_strHelpSet;
  275.     }
  276.     else
  277.     {
  278.         System.out.println("Unknown file extension name.");
  279.         bSuccess = false;
  280.     }
  281.  
  282.     //Build helpset object
  283.     if (bSuccess)
  284.     {
  285.       try
  286.       {
  287.         if (strHsUrl.length () != 0)
  288.         {
  289.           //a hs file
  290.           String      strHsWorkingFolder  = new String("");
  291.           strHsWorkingFolder = strHsUrl.substring(0, strHsUrl.lastIndexOf('/'));
  292.           helpset = new HelpSetFile(help, new URL(strHsUrl), new URL(strHsWorkingFolder));
  293.         }
  294.         else if (strJarName.length() != 0)
  295.         {
  296.           //a jar file
  297.           String strPackageName = strJarName;
  298.           String strClsName = "";
  299.  
  300.           //try to find the class in package
  301.           Class  clsName = null;
  302.           boolean bFindClass = false;
  303.           try
  304.           {
  305.             strClsName = strPackageName +"." + strJarName + "DocHelpSet";
  306.             clsName = Class.forName(strClsName);
  307.             bFindClass = true;
  308.           }
  309.           catch(Exception e)
  310.           {
  311.             //Ignore
  312.           }
  313.  
  314.           if (!bFindClass)
  315.           {
  316.             //try to find the class in unnamed package
  317.             try
  318.             {
  319.               strClsName = strJarName + "DocHelpSet";
  320.               clsName = Class.forName(strClsName);
  321.               bFindClass = true;
  322.             }
  323.             catch(Exception e)
  324.             {
  325.                //Ignore
  326.             }
  327.           }
  328.  
  329.           if (bFindClass)
  330.           {
  331.             String strHsName = strJarName + ".hs";
  332.             helpset = new HelpSetFile(help, clsName, strHsName);
  333.           }
  334.           else
  335.           {
  336.              System.out.println("Can not find class in jar file:" + strJarName + ".class" );
  337.              bSuccess = false;
  338.           }
  339.         }
  340.         else
  341.         {
  342.           System.out.println("No file name ?!");
  343.           bSuccess = false;
  344.         }
  345.       }
  346.       catch (Exception e)
  347.       {
  348.         e.printStackTrace();
  349.         bSuccess = false;
  350.       }
  351.     }
  352.  
  353.     if (!bSuccess)
  354.     {
  355.       System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
  356.     }
  357.     else
  358.     {
  359.       help.showContents();
  360.     }
  361.     return bSuccess;
  362.   }
  363. */
  364.  
  365. /*
  366.   //Help Launcher for OracleHelp 3.2.0~3.2.1 /4.1.0~4.1.1
  367.   public boolean HelpLauncher32(String a_strHelpSet, String a_strHelpId)
  368.   {
  369.     Help        help          = new Help();
  370.     HelpSet     helpset      = null;
  371.     String      strHsUrl      = "";
  372.     String      strJarName    = "";
  373.  
  374.     boolean bSuccess = true;
  375.  
  376.     if (a_strHelpSet.endsWith(".jar"))
  377.     {
  378.       //Compressed help in jar,  the class inside the jar should be "FileName"+"DocHelpSet"
  379.       //and located either in "FileName".toLowCase() package or Unnamed Package
  380.       strJarName = new String("");
  381.       strJarName = a_strHelpSet.substring (0,a_strHelpSet.length()-4);
  382.     }
  383.     else if (a_strHelpSet.endsWith(".hs"))
  384.     {
  385.         //Helpset file
  386.         if (a_strHelpSet.charAt(0) == '/')
  387.           strHsUrl = "file:"  + a_strHelpSet;
  388.         else
  389.           strHsUrl = "file:/" + a_strHelpSet;
  390.     }
  391.     else
  392.     {
  393.         System.out.println("Unknown file extension name.");
  394.         bSuccess = false;
  395.     }
  396.  
  397.     //Build helpset object
  398.     if (bSuccess)
  399.     {
  400.       try
  401.       {
  402.         if (strHsUrl.length () != 0)
  403.         {
  404.           //a hs file
  405.           helpset = new HelpSet(new URL(strHsUrl));
  406.         }
  407.         else if (strJarName.length() != 0)
  408.         {
  409.           //a jar file
  410.           String strPackageName = strJarName;
  411.           String strClsName = "";
  412.  
  413.           //try to find the class in package
  414.           Class  clsName = null;
  415.           boolean bFindClass = false;
  416.           try
  417.           {
  418.             strClsName = strPackageName +"." + strJarName + "DocHelpSet";
  419.             clsName = Class.forName(strClsName);
  420.             bFindClass = true;
  421.           }
  422.           catch(Exception e)
  423.           {
  424.             //Ignore
  425.           }
  426.  
  427.           if (!bFindClass)
  428.           {
  429.             //try to find the class in unnamed package
  430.             try
  431.             {
  432.               strClsName = strJarName + "DocHelpSet";
  433.               clsName = Class.forName(strClsName);
  434.               bFindClass = true;
  435.             }
  436.             catch(Exception e)
  437.             {
  438.                //Ignore
  439.             }
  440.           }
  441.  
  442.           if (bFindClass)
  443.           {
  444.             String strHsName = strJarName + ".hs";
  445.             helpset = new HelpSet(clsName, strHsName);
  446.           }
  447.           else
  448.           {
  449.              System.out.println("Can not find class in jar file:" + strJarName + ".class" );
  450.              bSuccess = false;
  451.           }
  452.         }
  453.         else
  454.         {
  455.           System.out.println("No file name ?!");
  456.           bSuccess = false;
  457.         }
  458.       }
  459.       catch (Exception e)
  460.       {
  461.         e.printStackTrace();
  462.         bSuccess = false;
  463.       }
  464.     }
  465.  
  466.     if (!bSuccess)
  467.     {
  468.       System.out.println("Fail to lanuch OracleHelp : " + a_strHelpSet);
  469.     }
  470.     else
  471.     {
  472.       Book book = (Book)helpset;
  473.       help.addBook(book);
  474.       help.showNavigatorWindow();
  475.  
  476.     }
  477.     return bSuccess;
  478.   }
  479. */
  480. }
  481.  
  482.